#include "mockcpp/mockcpp.hpp"
#include "gtest/gtest.h"

#include <iostream>
#include <stdio.h>

#include "aa.binary_search.h"
#include "ab.sort.h"
#include "ac.greedy.h"

#include "pub.h"

// setuptestcase fixture
// setup everycase

extern "C" {
}

class LeetcodeTest : public ::testing::Test {
  protected:
    virtual void SetUp() { std::cout << "setup executor" << std::endl; }
    virtual void TearDown()
    {
        std::cout << "teardown executor" << std::endl;
        GlobalMockObject::verify();
    }
    static void SetUpTestCase() { std::cout << "setup by case" << std::endl; }
    static void TearDownTestCase()
    {
        std::cout << "teardown by case" << std::endl;
    }
};

TEST_F(LeetcodeTest, Test_0069)
{
    typedef struct {
        char *caseName;
        int   input;
        int   expect;
    } LeetCode0069;

    LeetCode0069 testCaseTbl[] = {
        {"case-01", 9, 3},
        {"case-02", 4, 2},
        {"case-03", 8, 2},
        {"case-04", 0, 0},
        // {"case-05", (1 << 31) - 1, 18},
    };

    int testLen = sizeof(testCaseTbl) / sizeof(LeetCode0069);
    int i;
    for (i = 0; i < testLen; i++) {
        LeetCode0069 *tc = &testCaseTbl[i];
        printf("[test] test %s\n", tc->caseName);
        int got = mySqrt(tc->input);
        ASSERT_EQ(got, tc->expect);
    }
}

TEST_F(LeetcodeTest, Test_0215)
{
    typedef struct {
        char *caseName;
        int * inputPtr;
        int   inputLen;
        int   k;
        int   expect;
    } LeetCode0215;
    int a[6] = {3, 2, 1, 5, 6, 4};

    LeetCode0215 testCaseTbl[] = {
        {"case-01", a, 6, 2, 0},
    };

    int testLen = sizeof(testCaseTbl) / sizeof(LeetCode0215);
    int i;
    for (i = 0; i < testLen; i++) {
        LeetCode0215 *tc = &testCaseTbl[i];
        printf("[test] test %s\n", tc->caseName);
        int got = findKthLargest(tc->inputPtr, tc->inputLen, tc->k);
        ASSERT_EQ(got, tc->expect);
    }
}

TEST_F(LeetcodeTest, Test_0053)
{
    int expect, got;

    // int numArr[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
    // expect = 6;

    int testTbl[][100] = {
        {-100000},
        {-1},
        {-2, 1, -3, 4, -1, 2, 1, -5, 4},
    };

    // int numArr[] = {-100000};
    // expect       = -100000;

    // int numLen = sizeof(numArr) / sizeof(int);

    // got = maxSubArray(numArr, numLen);

    // ASSERT_EQ(got, expect);

    typedef struct {
        char *caseName;
        int * inputHdr;
        int   inputLen;
        int   expect;
    } LeetCode0053;

    // int a[6] = {3, 2, 1, 5, 6, 4};

    LeetCode0053 testCaseTbl[] = {
        {"case-01", testTbl[0], 1, -100000},
        {"case-01", testTbl[1], 1, -1},
        {"case-01", testTbl[2], 9, 6},
    };

    int testLen = sizeof(testCaseTbl) / sizeof(LeetCode0053);
    int i;
    for (i = 0; i < testLen; i++) {
        LeetCode0053 *tc = &testCaseTbl[i];
        printf("[test] test %s\n", tc->caseName);
        int got = maxSubArray(tc->inputHdr, tc->inputLen);
        ASSERT_EQ(got, tc->expect);
    }
}
